package com.dream.springmvc.value;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author zhaoshichang
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AmountValue implements Value<Double> {
    private Double value;
    private String unit;

    @JsonCreator
    public static AmountValue fromJson(String val) {
        String[] amountVal = val.split(" ");
        if (amountVal.length != 2) {
            throw new RuntimeException("amount value not valid.");
        }
        return new AmountValue(Double.valueOf(amountVal[0]), amountVal[1]);
    }
}
